from manim import *

class NaturalNumbersIntroduction(Scene):
    def construct(self):
        # 标题
        title = Text("自然数的概念", font_size=48, color=YELLOW)
        self.play(Write(title))
        self.wait(1)
        self.play(title.animate.to_edge(UP))

        # 自然数集合
        natural_numbers = MathTex(r"\mathbb{N} = \{1, 2, 3, 4, 5, \ldots\}", font_size=36)
        natural_numbers.next_to(title, DOWN, buff=1)
        self.play(Write(natural_numbers))
        self.wait(1)

        # 特性 1: 计数
        counting_title = Text("计数", font_size=36, color=BLUE)
        counting_title.next_to(natural_numbers, DOWN, buff=1)
        self.play(Write(counting_title))

        counting_example = VGroup(
            MathTex("1", font_size=36),
            MathTex("2", font_size=36),
            MathTex("3", font_size=36),
            MathTex("4", font_size=36),
            MathTex("5", font_size=36)
        ).arrange(RIGHT, buff=0.5).next_to(counting_title, DOWN, buff=0.5)
        self.play(Write(counting_example))
        self.wait(2)

        self.play(FadeOut(counting_title), FadeOut(counting_example))

        # 特性 2: 排序
        ordering_title = Text("排序", font_size=36, color=GREEN)
        ordering_title.next_to(natural_numbers, DOWN, buff=1)
        self.play(Write(ordering_title))

        ordering_example = VGroup(
            MathTex("1 < 2", font_size=36),
            MathTex("3 < 4", font_size=36),
            MathTex("4 < 5", font_size=36)
        ).arrange(DOWN, buff=0.5).next_to(ordering_title, DOWN, buff=0.5)
        self.play(Write(ordering_example))
        self.wait(2)

        self.play(FadeOut(ordering_title), FadeOut(ordering_example))

        # 特性 3: 加法和乘法
        operations_title = Text("加法和乘法", font_size=36, color=RED)
        operations_title.next_to(natural_numbers, DOWN, buff=1)
        self.play(Write(operations_title))

        operations_example = VGroup(
            MathTex("2 + 3 = 5", font_size=36),
            MathTex("4 \\times 2 = 8", font_size=36)  # 修改乘法符号
        ).arrange(DOWN, buff=0.5).next_to(operations_title, DOWN, buff=0.5)
        self.play(Write(operations_example))
        self.wait(2)

        self.play(FadeOut(operations_title), FadeOut(operations_example))

        # 总结
        summary = Text("自然数是数学的基础，应用广泛且深远。", font_size=36, color=WHITE)
        summary.next_to(natural_numbers, DOWN, buff=1)
        self.play(Write(summary))
        self.wait(2)

# 运行代码
# 保存修改后的 Python 文件（例如 NaturalNumbersIntroduction.py），然后在命令行中运行以下命令：
# manim -pql .\NaturalNumbersIntroduction.py NaturalNumbersIntroduction